package com.heima.wemedia.feign;

import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.admin.admin.ChannelDto;
import com.heima.model.admin.dtos.NewsAuthDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmChannelDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.mapper.WmUserMapper;
import com.heima.wemedia.service.WemediaClientService;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmSensitiveService;
import com.heima.wemedia.service.WmUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@Slf4j
public class WemediaClient implements IWemediaClient {
    @Autowired
    private WemediaClientService wemediaClientService;

    @Autowired
    private WmSensitiveService sensitiveService;

    @Autowired
    private WmUserService wmUserService;
//-------------------------------------wu
    @Override
    @PostMapping("/api/v1/news/list_vo")
    public PageResponseResult newListVo(@RequestBody NewsAuthDto dto) {
        log.info("newListVo参数为:{}",dto);
        return wemediaClientService.newListVo(dto);
    }

    /**
     * 查询单个文章详情
     *
     * @param wmNewsId
     * @return
     */
    @Override
    @GetMapping("/api/v1/news/one_vo/{id}")
    public ResponseResult oneVoById(@PathVariable("id") Integer wmNewsId) {
        log.info("oneVoById参数为:{}",wmNewsId);
        return wemediaClientService.oneVoById(wmNewsId);
    }

    /**
     * 成功审核
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/api/v1/news/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto) {
        log.info("authPass参数为:{}",dto);
        return wemediaClientService.authPass(dto);
    }

    /**
     * 失败审核
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/api/v1/news/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto) {
        log.info("authFail参数为:{}",dto);
        return wemediaClientService.authFail(dto);
    }

    @PostMapping("/api/v1/login/wm_register")
    @Override
    public ResponseResult wmRegister(@RequestBody WmUser wmUser) {
        return wmUserService.wmRegister(wmUser);
    }

    //-----------------------------------------徐

    @Override
//    删除敏感词 返回结果
    @DeleteMapping("/api/v1/sensitive/del/{id}")
    public ResponseResult DeleteSensitive(Integer id) {

        boolean b = sensitiveService.deleteByid(id);
        if (b==true){
            return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

    @Override
    @PostMapping("/api/v1/sensitive/save")
    public ResponseResult Save(WmSensitive wmSensitive) {

        return sensitiveService.Save(wmSensitive);
    }


    @Override
    @PostMapping("/api/v1/sensitive/update")
    public ResponseResult Update (WmSensitive wmSensitive) {

        return sensitiveService.Update(wmSensitive);

    }


    @Override
    @PostMapping("/api/v1/sensitive/list")
    public ResponseResult SelectLike(Map map) {

        ResponseResult responseResult = sensitiveService.SelectLike(map);

        return responseResult;
    }

    /**
     * 查询所有敏感词
     */
    @Override
    @GetMapping("/api/v1/sensitive/listAll")
    public ResponseResult querySensitiveAll() {
        return sensitiveService.querySensitiveAll();
    }
    //-------------------------------wang

    @Autowired
    private WmChannelService wmChannelService;

    //新增频道
    @Override
    @PostMapping("/api/v1/channel/save")
    public ResponseResult saveChannel(@RequestBody WmChannelDto wmChannel) {
        return wmChannelService.saveChannel(wmChannel);
    }

    //分页查询频道
    @Override
    @PostMapping("/api/v1/channel/list")
    public ResponseResult sybaseChannels(@RequestBody ChannelDto dto) {
        return wmChannelService.sybaseChannels(dto);
    }

    //修改频道
    @Override
    @PostMapping("/api/v1/channel/update")
    public ResponseResult updateChannel(@RequestBody WmChannelDto wmChannel) {
        return wmChannelService.updateChannel(wmChannel);
    }

    //删除频道
    @Override
    @GetMapping("/api/v1/channel/del/{id}")
    public ResponseResult deleChannel(@PathVariable("id") Integer id) {
        return wmChannelService.deleChannel(id);
    }
}
